package main

import "fmt"

func defer1() {
	fmt.Println("defer1 invoke..")
}

func defer2() {
	fmt.Println("defer2 invoke..")
}

func returnFunc() {
	fmt.Println("return invoke..")
}

func deferAndReturn() {
	defer defer1()
	defer defer2()
	returnFunc()
}

func main6() {
	fmt.Println("defer在相当于整个函数执行完毕后，return后执行.相当于java中的finally.")
	fmt.Println("多个defer先进后出顺序执行，常用来释放资源.")
	deferAndReturn()
}
